home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / SYNAPSE / SUBSYN.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  2.7 KB  |  75 lines

  1. // Dynamic link library implementation of NeuroSolutions Synapse component 
  2.  
  3. #include "NSDLL.h"
  4.  
  5. /***********************************/
  6. /* Forward activation of component */
  7. __declspec(dllexport) void performSynapse(
  8.     DLLData *instance,    // Pointer to instance data (may be NULL)
  9.     NSFloat    *input,     // Pointer to the input layer of processing elements (PEs)
  10.     int     inRows,        // Number of rows of PEs in the input layer
  11.     int     inCols,        // Number of columns of PEs in the input layer
  12.     NSFloat    *output,     // Pointer to the output layer
  13.     int     outRows,    // Number of rows of PEs in the output layer
  14.     int     outCols        // Number of columns of PEs in the output layer
  15.     )
  16. {
  17.     BOOL    subInput = getBoolParameter(instance, 1, 1);
  18.     int    i,
  19.         inCount = subInput? getIntParameter(instance, 3, 1): inRows*inCols,
  20.         outCount = !subInput? getIntParameter(instance, 3, 1): outRows*outCols,
  21.         start = getIntParameter(instance, 2, 1),
  22.         count = inCount<outCount? inCount: outCount;
  23.  
  24.     if (subInput)
  25.         for (i=0; i<count; i++)
  26.             output[i] += input[i+start]; 
  27.     else
  28.         for (i=0; i<count; i++)
  29.             output[i+start] += input[i]; 
  30. }
  31.  
  32. /******************************************/
  33. /* Management of instance data (OPTIONAL) */
  34. __declspec(dllexport) DLLData *allocSynapse(
  35.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  36.     int     inRows,            // Number of rows of PEs in the input layer
  37.     int     inCols,            // Number of columns of PEs in the input layer
  38.     int     outRows,        // Number of rows of PEs in the output layer
  39.     int     outCols            // Number of columns of PEs in the output layer
  40.     )
  41. {
  42.     BOOL subInput;
  43.     int maxLength, start, length;
  44.     DLLData *instance = allocDLLInstance(oldInstance);
  45.     setParameterName(instance, 1, 1, "Input", TRUE);
  46.     setBoolParameter(instance, 1, 1, TRUE, FALSE);
  47.     setParameterName(instance, 2, 1, "Start", TRUE);
  48.     setIntParameter(instance, 2, 1, 0, FALSE);
  49.     setParameterName(instance, 3, 1, "Length", TRUE);
  50.     setIntParameter(instance, 3, 1, 1, FALSE);
  51.     subInput = getBoolParameter(instance, 1, 1);
  52.     maxLength = subInput? inRows*inCols: outRows*outCols;
  53.     start = getIntParameter(instance, 2, 1);
  54.     if (inRows && inCols && outRows && outCols) {
  55.         if (start >= maxLength)
  56.             start = maxLength-1;
  57.         length = getIntParameter(instance, 3, 1);
  58.         if (start+length > maxLength)
  59.             length = maxLength-start;
  60.         if (!subInput)
  61.             if (length > inRows*inCols)
  62.                 length = inRows*inCols;
  63.     } else
  64.         start = length = 0;
  65.     setBoolParameter(instance, 1, 1, subInput, TRUE);
  66.     setIntParameter(instance, 2, 1, start, TRUE);
  67.     setIntParameter(instance, 3, 1, length, TRUE);
  68.     return instance;
  69. }
  70.  
  71. __declspec(dllexport) void freeSynapse(DLLData *instance)
  72. {
  73.     freeDLLInstance(instance);
  74. }
  75.